package com.jie.erp.springbootjieerp.config;


import com.jie.erp.springbootjieerp.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class JepMvcConfig implements WebMvcConfigurer {


    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("/login");
        registry.addViewController("/index.html").setViewName("/login");
        registry.addViewController("/main.html").setViewName("/dashboard");
        registry.addViewController("/saveUser").setViewName("emp/add");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        List<String> excludes=new ArrayList<String>();
        excludes.add("/asserts/**");
        excludes.add("/webjars/**");
        excludes.add("/img/**");
        excludes.add("/js/**");
        excludes.add("/user/login");
        excludes.add("/index.html");
        excludes.add("/");
        registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/**")
                .excludePathPatterns(excludes);
    }
}
